package com.example.common.core.controller;

import com.example.common.core.model.R;
import com.example.common.core.model.TableDataInfo;
import com.github.pagehelper.PageInfo;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 功能描述:
 *
 * @author Lenovo
 * @date 2025/3/20
 */

public class BaseController {
    public R<Void> toResult(int row) {
        return row == 1 ? R.ok() : R.fail();
    }
    public R<Void> toResult(boolean result) {
        return result ? R.ok() : R.fail();
    }

    public TableDataInfo getTableDataInfo(List<?> list){
        if(CollectionUtils.isEmpty(list)){
            return TableDataInfo.empty();
        }
        return TableDataInfo.success(list, new PageInfo<>(list).getTotal());
    }
}
